package com.zjpavt.taiyuan.utils;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.naming.NoNameCoder;
import com.thoughtworks.xstream.io.xml.Xpp3Driver;

import java.util.List;

public class XmlUtil {

    public static String beanToString(Object o){
        XStream xStream = new XStream(new Xpp3Driver(new NoNameCoder()));
        xStream.aliasSystemAttribute(null,"class");
        xStream.autodetectAnnotations(true);
        String result = xStream.toXML(o);
        return result;
    }


    public static <T> List<T> stringToClass(String xml, Class<T> clazz){
        XStream xStream = new XStream();
        //自己实体类的路径
        xStream.autodetectAnnotations(true);
        xStream.processAnnotations(clazz);
        return (List<T>) xStream.fromXML(xml);
    }
}